package com.accessibleworlds.report;

import java.io.File;

import android.app.Activity;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.res.Configuration;
import android.os.Bundle;
import android.view.Window;
import android.widget.MediaController;
import android.widget.VideoView;

import com.accessibleworlds.R;
import com.accessibleworlds.util.SharedVariables;
	
/**
 * Lets users see images attached to reports in a sequential manner with swipe gestures.
 */
public class ReportVideoViewer extends Activity{
	
	private VideoView videoView;
	
	private String videoID;
	
	private Bundle bundle;

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);

		setContentView(R.layout.reportvideoviewer);
		
		initializeVariables();
    }
	
	@Override
	public void onBackPressed() {
		Intent intent = new Intent(ReportVideoViewer.this,ReportView.class);
		Bundle bundleSend = new Bundle();
		bundleSend.putString("previousID", bundle.getString("previousID"));
		bundleSend.putString("reportID", ""+bundle.getString("reportID"));
		bundleSend.putString("status", bundle.getString("status"));
		bundleSend.putString("type", ""+bundle.getString("type"));
		bundleSend.putString("title", bundle.getString("title"));
		bundleSend.putString("description", bundle.getString("description"));
		bundleSend.putString("latitude", ""+bundle.getString("latitude"));
		bundleSend.putString("longitude", ""+bundle.getString("longitude"));
		bundleSend.putString("rate", bundle.getString("rate"));
		intent.putExtras(bundleSend);
		startActivity(intent);
		overridePendingTransition(R.anim.fade, R.anim.hold);
		finish();
	}
	
	/**
	 * Initializes view elements.
	 */
	private void initializeVariables() {		
		bundle = getIntent().getExtras();
		videoID = bundle.getString("videoID");
		
		videoView = (VideoView) findViewById(R.id.reportvideoview);
		videoView.setVideoPath(SharedVariables.folderName+File.separator+videoID+".3gp");
        videoView.setMediaController(new MediaController(this));
        videoView.start();
        videoView.requestFocus();
	}
	
	@Override
    public void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);
        setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
    }
}